package com.hec.yygh.hosp.controller;

import com.hec.yygh.common.result.R;
import com.hec.yygh.hosp.service.HospitalService;
import com.hec.yygh.model.hosp.Hospital;
import com.hec.yygh.vo.hosp.HospitalQueryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/admin/hosp/hospital")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @GetMapping("/{page}/{limit}")
    public R getHospitalPage(@PathVariable("page") Integer page,
                             @PathVariable("limit") Integer limit,
                             HospitalQueryVo hospitalQueryVo){
        Page<Hospital> pageInfo = hospitalService.selectPage(page,limit,hospitalQueryVo);
        return R.ok().data("pages",pageInfo);
    }

    @PostMapping("/updateStatus/{id}/{status}")
    public R updateStatus(@PathVariable("id") String id,
                          @PathVariable("status") Integer status){
        hospitalService.updateStatus(id,status);
        return R.ok();
    }

    @GetMapping("/show/{id}")
    public R show(@PathVariable("id") String id) {
        Map<String, Object> map = hospitalService.show(id);
        return R.ok().data("hospital",map);
    }
}
